package com.eightywork.life.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.eightywork.life.R;
import com.eightywork.life.activity.IndexActivity;
import com.eightywork.life.fragment.CommunityFragment;
import com.eightywork.life.model.Tag;
import com.eightywork.life.service.DataService;

public class TagListAdapter extends ArrayAdapter<Tag> {
	private LayoutInflater mInflater;
	private int mResource = R.layout.item_community_type;
	private String tagId = "";
	private String tagName = "";

	public void setTagId(String tagId) {
		this.tagId = tagId;
	}

	public TagListAdapter(Context context, List<Tag> list) {
		super(context, 0, list);
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, final ViewGroup parent) {
		View layout = convertView;
		if (layout == null) {
			layout = mInflater.inflate(mResource, parent, false);
		}
		final Tag tag = getItem(position);
		TextView view = (TextView) layout;
		view.setText(tag.getTagname());
		if (tagId.equals(tag.getTagid())) {
			view.setBackgroundResource(R.drawable.com_type1);
		} else {
			view.setBackgroundResource(R.drawable.com_type0);
		}
		return layout;
	}

	public String getTagName() {
		return tagName;
	}

	public void setTagName(String tagName) {
		this.tagName = tagName;
	}

	public String getTagId() {
		return tagId;
	}
}
